import 'package:htxd_flutter_mapbox_sdk/entity/point_entity.dart';
import 'package:htxd_flutter_mapbox_sdk/mapbox/util/uuid_util.dart';

class VillageLandEntity {
  String? time; // 时间，年份
  String? landArea; // 地块面积
  String? insured; // 被保险人
  String? insurance; // 险种
  String? deadline; // 期限
  bool? flag; //  是否参与 覆盖率的计算
  bool? isSelect; // 是否选中，用于筛选所用
  String? uuid; // uuid，用于进行区分
  List<PointEntity>? path;

  VillageLandEntity(
      {this.time,
      this.landArea,
      this.insured,
      this.insurance,
      this.deadline,
      this.flag = true,
      this.isSelect = false,
      this.uuid,
      this.path}) {
    uuid = uuid ?? UuidUtil.instance.getUuid();
  }

  VillageLandEntity.fromJson(dynamic json) {
    time = json['time'];
    landArea = json['landArea'];
    insured = json['insured'];
    insurance = json['insurance'];
    deadline = json['deadline'];
    flag = json['flag'] ?? true;
    isSelect = json['isSelect'] ?? false;
    uuid = json['uuid'] ?? UuidUtil.instance.getUuid();
    if (json['path'] != null) {
      path = [];
      json['path'].forEach((v) {
        path?.add(PointEntity.fromJson(v));
      });
    }
  }

  VillageLandEntity copyWith(
          {String? time,
          String? landArea,
          String? insured,
          String? insurance,
          String? deadline,
          bool? flag,
          bool? isSelect,
          String? uuid,
          List<PointEntity>? path}) =>
      VillageLandEntity(
        time: time ?? this.time,
        landArea: landArea ?? this.landArea,
        insured: insured ?? this.insured,
        insurance: insurance ?? this.insurance,
        deadline: deadline ?? this.deadline,
        flag: flag ?? this.flag,
        isSelect: isSelect ?? this.isSelect,
        uuid: uuid ?? this.uuid,
        path: path ?? this.path,
      );

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['time'] = time;
    map['landArea'] = landArea;
    map['insured'] = insured;
    map['insurance'] = insurance;
    map['deadline'] = deadline;
    map['flag'] = flag;
    map['isSelect'] = isSelect;
    map['uuid'] = uuid;
    if (path != null) {
      map['path'] = path?.map((v) => v.toJson()).toList();
    }
    return map;
  }
}
